<%@ page language="java" pageEncoding="utf-8" %>
<%@ include file="/include/taglibs.jsp" %>

<div>


    <script class="editor" id="editor" type="text/plain" style="width:1024px;height:500px;"></script>

    <label id="path"></label>
    <br/>
    <button id="save" class="btn btn-default">save</button>
    <button id="load" class="btn btn-default">load</button>

    <script>

       // var editor = $(".editor");
      //  alert(editor.attr("editorId"));
//        var loadUE = function () {
//            var editor = $(".editor");
//            if (editor != null) {
//                var id = editor.attr("id");
//                var showId = "show" + id;
//                var editorId = "editor" + id;
//                if (id != null) {
//                    if (!window[showId]) {
//                        window[showId] = 1;
//                        window[editorId] = UE.getEditor(id);
//                    } else {
//                        window[editorId].destroy();
//                        window[editorId] = UE.getEditor(id);
//                    }
//                }
//            }
//        }
//
//        loadUE();
//
//        var getUE = function () {
//            var editor = $(".editor");
//            if (editor != null) {
//                var id = editor.attr("id");
//                var showId = "show" + id;
//                var editorId = "editor" + id;
//                if (id != null) {
//                    if (window[showId] == 1) {
//                        return window[editorId];
//                    }
//                }
//            }
//            return null;
//        }

        //        if(!window.isShowEditor){
        //            window.isShowEditor = 1;
        //            window.showEditor = UE.getEditor('editor');
        //        }else{
        //            window.showEditor.destroy();
        //            window.showEditor = UE.getEditor('editor');
        //        }


        bindClick("#save", function () {
            var ue = UE.getEditor('editor');
            var content = ue.getContent();
            var path = $("#path").text();
            var params = {content: content, path: path};
            comment.post('/web/baidu/save', params, null, function (res) {
                var dataPath = res.res.data.back;
                $("#path").text(dataPath);
            });
        });
        bindClick("#load", function () {
            comment.post('/web/baidu/load', {path: $("#path").text()}, null, function (res) {
                var dataPath = res.res.data;
                var ue =UE.getEditor('editor');
                ue.setContent(dataPath);
            });
        });
    </script>

</div>
